package com.app.widget

import android.app.Activity
import android.content.res.Resources
import android.util.TypedValue
import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment

val @receiver:ColorRes Int.colorValue get() = Resources.getSystem().getColor(this)

//val @receiver:StringRes Int.strValue get() = Resources.getSystem().getString(this)
inline fun Fragment.text(@StringRes id:Int) = resources.getString(id)
inline fun Activity.text(@StringRes id:Int) = resources.getString(id)
inline fun View.text(@StringRes id:Int) = resources.getString(id)
val Float.dp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        this,
        Resources.getSystem().displayMetrics
    )

val Int.dp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        this.toFloat(),
        Resources.getSystem().displayMetrics
    ).toInt()

val Float.sp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_SP,
        this,
        Resources.getSystem().displayMetrics
    )

val Int.sp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_SP,
        this.toFloat(),
        Resources.getSystem().displayMetrics
    ).toInt()